<template>
  <div style="height:100%" v-loading="loading">
    <v-tableTitle :btnConfig="btnConfig" :title="$t('wave.wavestrgroup')" @newCreate="newCreate" @del="del"></v-tableTitle>
    <ag-grid class="base-grid" :hasCheck="true" :hasIndex="false" :hasEdit="true" v-model="gridObj"
      :defaultColDef="defaultColDef" :highlightCurrentRow="false" :disabled="true" :data="rowData" :rules="rules"
      :height="height" :tmsShowFilter="true" :columnConfig="columnConfig"
      :extraColumns="extraColumns" :showSummary="false" :pagination="true" :tableSettingVisible.sync="showTableSetting"
      :page="page" :pageSize="pageSize" :total="total" @selection-change="handleSelectionChange"
      @size-change="handleSizeChange" @current-change="handleCurrentChange" @setdialog="setdialog"
      @filter-changed="filterChanged" @cell-dblclick="cellDblclick" @grid-ready="agGridReady">
    </ag-grid>
  </div>
</template>

<script>
import { getOutWaveStrategyGroupEntryList, outWaveStrategyGroupDelete } from "@/api/business/wave"
import baseMixin from "@/mixins/BaseMixin";
import agGridBaseMixin from "@/mixins/AgGridBaseMixin";

export default {
  name: "outWaveStrategyGroup",
  mixins: [baseMixin, agGridBaseMixin],
  data() {
    return {
      height: 0,
      columnConfig:{ menu_id: 946, menu_code:"outWaveStrategyGroup", menu_list_code:"outWaveStrategyGroup", },
      defaultColDef: {
      }
    }
  },
  computed: {
    btnConfig() {
      return [
        { label: this.$t('common.create'), certigier: this.newStatus||!this.btnPermNameList.includes('WM05010201'), invalid: "newCreate" },
        { label: this.$t('common.delete'), certigier: this.delStatus||!this.btnPermNameList.includes('WM05010202'), invalid: "del" },
      ];
    }
  },
  mounted() {
    this.height = this.getHeight(window,60);
    this.$store.commit("setSkip", {});
    this.$store.commit("setRouteId", "");
    this.$store.commit("setNewFlag", false);
    this.$store.commit("setRouteData", {});
    this.getTableData(1, {});
  },
  methods: {
    del() {
      let selectedList = this.gridObj.getSelectedRows();
      if (selectedList.lenght === 0 || selectedList === null || selectedList === undefined) {
        this.$message.error(this.$t('msg.msg12'));
        return;
      };
      let data = [];
      selectedList.forEach((item) => {
        data.push({ id: item.id });
      })
      outWaveStrategyGroupDelete(data).then(res => {
         console.log(res);
          this.$message.success(this.$t('app.delMes'));
          this.getTableData(1, {});
        
      })
    },
    newCreate() {
      this.$store.commit("setNewFlag", true);
      this.$router.push({ name: 'outWaveStrategyGroupDeawer' });
    },
    agGridReady(params) {
      this.gridObj = params.api;
    },
    setdialog(data) {
      this.$store.commit("setRouteData", data);
      this.$router.push({ name: 'outWaveStrategyGroupDeawer' });
    },
    getTableData(page, data) {
      if (data === undefined || data === null || !data) {
        data = {};
      }
      getOutWaveStrategyGroupEntryList(page, data).then(res => {
          this.rowData = res.page.list;
          this.page = res.page.currentPage;
          this.pageSize = res.page.pageSize;
          this.total = res.page.total;
        
      });
    }
  }
}
</script>

<style>
</style>
